package org.lex.ftp.ui.queue;

import java.awt.Component;

import javax.swing.JLabel;
import javax.swing.JTable;
import javax.swing.table.DefaultTableCellRenderer;

import org.lex.ftp.queue.Task;
import org.lex.utils.text.SizeFormat;


public class SizeRenderer extends DefaultTableCellRenderer {
	private static final SizeRenderer instance;
	static {
		instance = new SizeRenderer();
		instance.setHorizontalAlignment(JLabel.RIGHT);
	}

	public static SizeRenderer getInstance() {
		return instance;
	}

	@Override
	public Component getTableCellRendererComponent(JTable table, Object value, boolean isSelected, boolean hasFocus, int row, int column) {
		if (null == value)
			return this;
		Task task = (Task) value;
		String size = SizeFormat.autoFormat(task.getLength());
		super.getTableCellRendererComponent(table, size, isSelected, hasFocus, row, column);
		return this;
	}
}
